import Mock from 'mockjs'

const Random = Mock.Random

/**
 * 7.3 组件开通
 * @type {*|{valid: *, XHR: *, RE: *, _mocked: {}, Random: *, toJSONSchema: *, Handler: *, setup: function(*): *, Util: *, heredoc: *}}
 */

// 资源池列表
export const res_pools = Mock.mock({
    'code': 0,
    'data|10': [
        {
            'resPoolId|+1': 1,
            'resPoolCode': '@name',
            'resPoolName': '@cname',
            'iaasTypeCode': Random.pick(['ctyun40', 'ctyun', 'itcmp', 'noiaas'])
            // 'iaasTypeCode': '@name'
        }
    ]
})

// 产品规格
export const order_spu = Mock.mock({
    'code': 0,
    'data|2': [
        {
            'spuCode': Random.string(10),
            'spuName': '@cname',
            'seriesCode': '@name',
            'seriesName': '@cname',
            'skuCode': Random.string(8),
            'skuName': '@name',
            'skuDesc': '@name',
            'skuAttrs|3': [
                {
                    'attrCode': Random.string(10),
                    'attrName': '@cname',
                    'attrType': '@pick(["0", "1"])',
                }
            ],
            'versions|2': [
                {
                    'versionNo': '@pick(["2.8.5", "2.8.6"])',
                    'versionDesc': '@pick(["2.8.5 版本", "2.8.6 版本"])',
                }
            ],
            'resTplDetails|2': [
                {
                    'resTplDetailName': '@pick(["缓冲节点1", "缓冲节点2"])',
                    'resTplDetailCode': 'cache',
                    'resourceTye': '@pick([1, 0, 4])',
                    'cpu': 4,
                    'memory': 16,
                    'diskSpace': 40,
                    'diskType': '@pick([1, 2, 3])',
                    'number': 2,
                    'maxNumber': 3
                }
            ]
        }
    ]
})

// 组件版本查询接口
export const project_version = Mock.mock({
    'projectCode': '',
    'projectVersionNos': ['1.0.0', '2.0.0', '3.0.0']
})

// 组件介质查询接口 TODO 有不确定返回格式
export const project_medium = Mock.mock({
    'projectCode': '',
    'projectVersionNo': '@pick(["2.8.5", "2.8.6"])',
    'status': '@pick([1, 2, 3, 4])',
    'projectAttaches': [
        {
            'fileName': '',
            'fileUrl': '',
            'fileMd5': '',
            'attachType': 0,
        }
    ],
    'moduleVersions': [
        {
            'Status': '@pick([1, 2, 3, 4])',
            'moduleCode': '',
            'moduleName': '',
            'projectCode': '',
            'projectVersion': '',
            'moduleId': 0,
            'moduleClass': 0,
            'versionId': 0,
            'moduleVersionNo': '',
            'versionFile': {
                'fileMd5': '',
                'fileName': '',
                'fileUrl': '',
                'attachType': 0,
            }
        }
    ],

})

// 组件介质下载接口 TODO 最后在弄

// 查询租户自管主机
// export const hosts = Mock.mock({
//     'code': 0,
//     'data': {
//         'size': 10,
//         'total': 1,
//         'pages': 1,
//         'list|10': [
//             {
//                 'hostId|+1': 1,
//                 'poolCode': Random.string(10),
//                 'vpcCode': Random.string(10),
//                 'subNetCode': Random.string(10),
//                 'machine': '@pick([0, 1, 2])',
//                 'cpu': Random.integer(1, 10),
//                 'memory': '@pick([4, 8, 16])',
//                 'osType': '@pick([0, 1, 2, 3, 4])',
//                 'osVersion': Random.string(10),
//                 'osName': Random.string(10),
//                 'cpuType': '@pick([10, 20, 30, 40])',
//                 'cpuName': Random.string(10),
//                 'totalDisk': Random.integer(1000, 20000),
//                 'diskType': '@pick([0, 1, 2, 3])',
//                 'hostName': Random.string(10),
//                 'hostAlias': Random.string(10),
//                 'hostCode': Random.string(10),
//                 'sshPort': Random.integer(3000, 9000),
//                 'hostDesc': Random.string(100),
//                 'hostIps': [
//                     {
//                         'hostIp': Random.string(10),
//                         'netFlag': '@pick([0, 1, 2, 3])',
//                         'ipType': '@pick([1, 2])',
//                     }
//                 ],
//             }
//         ],
//     }
// })

export const hosts = Mock.mock({
    'data|100': [
        {
            'hostId|+1': 1,
            'poolCode': Random.string(10),
            'vpcCode': Random.string(10),
            'subNetCode': Random.string(10),
            'machine': '@pick([0, 1, 2])',
            'cpu': Random.integer(1, 10),
            'memory': '@pick([4, 8, 16])',
            'osType': '@pick([0, 1, 2, 3, 4])',
            'osVersion': Random.string(10),
            'osName': Random.string(10),
            'cpuType': '@pick([10, 20, 30, 40])',
            'cpuName': Random.string(10),
            'totalDisk': Random.integer(1000, 20000),
            'diskType': '@pick([0, 1, 2, 3])',
            'hostName': Random.string(10),
            'hostAlias': Random.string(10),
            'hostCode': Random.string(10),
            'sshPort': Random.integer(3000, 9000),
            'hostDesc': Random.string(100),
            'hostIps': [
                {
                    'hostIp': Random.string(10),
                    'netFlag': '@pick([0, 1, 2, 3])',
                    'ipType': '@pick([1, 2])',
                }
            ],
        }
    ]
})

// 产品订购下单
export const placeNewPurchaseOrder = Mock.mock({
    'sourceSeq': '',
    'orderId': Random.integer(1000, 9999),
    'orderNbr': Random.string(10),
    'totalPrice': '@pick(["10.0", "20.0"])',
    'tariffUnit': '元/小时',
    'spuInsts': [
        {
            'spuInstId': Random.string(20)
        }
    ],
})

// 产品扩容下单
export const placeExpansionOrContractionOrder = Mock.mock({
    'sourceSeq': '',
    'orderId': Random.integer(1000, 9999),
    'orderNbr': Random.string(10),
    'totalPrice': '@pick(["10.0", "20.0"])',
    'tariffUnit': '元/小时'
})

// 产品退订下单/产品恢复下单/产品注销下单
export const placeUnsubscribeOrRecoverOrDestroyOrder = Mock.mock({
    'sourceSeq': '',
    'orderId': Random.integer(1000, 9999),
    'orderNbr': Random.string(10)
})

// 产品订单询价
export const queryOrderPrice = Mock.mock({
    'totalPrice': '@pick(["10.0", "20.0"])',
    'tariffUnit': '元/小时',
    'priceItems': [
        {
            'resourceName': '@cname',
            'resourceType': '@name',
            'price': '@pick(["10.0", "20.0"]',
            'count': Random.integer(1, 9),
            'totalPrice': '@pick(["10.0", "20.0"])',
            'tariffUnit': '个/小时',
        }
    ]
})

// 用户查询
export const userInfo = Mock.mock({
    'userId': Random.integer(1,99),
    'accountType': Random.integer(1,99),
    'userName': 'root',
    'realName': '超级管理员',
    'mobilephone': new RegExp('^1[3456789]\\d{9}$'),
    'email': '@email',
    'tenants': [
        {
            'tenantId': Random.integer(1,99),
            'tenantName': '@cname',
            'description': '@cname',
            'owner': '@name',
            'tenantCode': '@name',
            'children': [],
        }
    ]
})

// 校验ticket
export const ticket_res = Mock.mock(`

    <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
    <cas:authenticationSuccess>
        <cas:user>admin</cas:user>
        <cas:attributes>
            <cas:accountType>1</cas:accountType>
            <cas:mobile>18925012678</cas:mobile>
            <cas:userName>admin</cas:userName>
            <cas:userId>100001</cas:userId> 
            <cas:realName>管理员</cas:realName>
            <cas:email>admin@admin.cnmm</cas:email>
        </cas:attributes>
    </cas:authenticationSuccess>
</cas:serviceResponse>

`)











